package com.example.permission.controller;

import com.example.permission.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.HttpRequestHandler;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Set;

@Controller
public class loginController {

    @Autowired
    private UserService userService;

    @RequestMapping("/")
    public String toLogin(){
        return "redirect:/index";
    }

    /**
     * 跳转到登陆页面
     * @return
     */
    @RequestMapping("/toLoginPage")
    public String getLogin(){
        return "login";
    }

    /**
     * 跳转到首页
     * @return
     */
    @RequestMapping("/index")
    public String getMain(HttpServletRequest request){
        Set<String> name = userService.getPermission();
        request.getSession().setAttribute("permissionNames",name);
        return "dashboard";
    }
}
